package InformationRetriever.QueryMethods;

import Database.Document;
import Database.DocumentVector;

import java.util.Comparator;

public class ManhattanDistanceQuery extends QueryBase implements Comparator<Document>
{    
    public DocumentVector PerformQuery(String query)
    {
        return this.getSortedDocuments(query, this);
    }
    
    public double compareToQuery(Document o)
    {
        ///get (column) index of document o in transposed v2...
        int index = documents.indexOf(o);
        
        ///apply the formula...
        double sigmaOfAbsOfDifferences = 0;
        for(int i = 0; i < transposedV2.getRowDimension(); i++)
            sigmaOfAbsOfDifferences += Math.abs(queryVectorInTransposedV2.get(0,i) - transposedV2.get(i,index));
        
        return sigmaOfAbsOfDifferences;
    }

    public int compare(Document o1, Document o2)
    {
        return (int)(compareToQuery(o1)*1000 - compareToQuery(o2)*1000);
    }
    
    public boolean equals(Object obj)
    {
        return false;
    }
}